Skip to main content

Untyped lambda calculus

Notes taken from Type Theory and Formal proof. An introduction

Construction principles​

  1. Abstraction: λx.M.\lambda x.M. (read as abstraction of M over x)
  2. Application MNM N (read as application of M to N).

If it is necessary, some parentheses should be added during the construction process. e.g

Abstraction of yy over λ.x−y\lambda. x - y

λy.(λx.x−y)\lambda y.(\lambda x. x - y)

Functions of more than one argument: Currying​

The function f(x,y)=x2+yf(x, y) = x^2 + y can be write as λx.(λy.(x2+y))\lambda x. (\lambda y. (x^2 + y)).

Lambda terms​

Expressions in the lambda calculus are called λ−term\lambda-term. Λ\Lambda is the set of all λ−terms\lambda-terms. To start with, we assume the existence of an infinite set VV of so-called variables: V={x,y,z,..}V = \{x, y, z, ..\}

  1. Variable: if u∈Vu \in V, then u∈Λu \in \Lambda
  2. Application: if MM and N∈ΛN \in \Lambda, then (MN)∈Λ(M N) \in \Lambda
  3. Abstraction if u∈Vu \in V and M∈ΛM \in \Lambda, then (λu.M)∈Λ(\lambda u. M) \in \Lambda

so, Λ=V∣(ΛΛ)∣(λV.Λ)\Lambda = V|(\Lambda \Lambda)|(\lambda V. \Lambda)

Subterms​

All λ−term\lambda-term has sub terms defined as:

  1. Basis: Sub(x)={x}Sub(x) = \{x\}, for each x∈Vx \in V
  2. Application: Sub((MN))=Sub(M)∪Sub(N)∪{(MN)}Sub((M N)) = Sub(M) \cup Sub(N) \cup \{(M N)\}
  3. Abstraction: Sub((λx.M))=Sub(M)∪{(λx.M)}Sub((\lambda x.M)) = Sub(M) \cup \{(\lambda x.M)\}

Subterm properties​

  1. Reflexivity: For all λ−terms M\lambda-terms\ M, we have M∈Sub(M)M \in Sub(M)
  2. Transitivity: If L∈Sub(M)L \in Sub(M) and M∈Sub(N)M \in Sub(N), then L∈Sub(N)L \in Sub(N)

Proper subterm​

LL is a proper subterm of MM if LL is a subterm of MM, but L≢ML \not \equiv M

Free and bound variables​

  1. binding variable: variable after λ\lambda e.g. λx.\lambda x.
  2. bound variable: If a binding variable is used in the expression it is bound in the expression

Free variables definition​

FVFV is the set of free variables of a λ−term\lambda-term

  1. Variable: FV(x)={x}FV(x) = \{x\}
  2. Application: FV(MN)=FV(M)∪FV(N)FV(MN) = FV(M) \cup FV(N)
  3. Abstraction: FV(λx.M)=FV(M)∖{x}FV(\lambda x. M) = FV(M) \setminus \{x\}

Closed λ−term\lambda-term​

The λ−term\lambda-term MM is closed if FV(M)=∅FV(M) = \emptyset. A closed λ−term\lambda-term is also called a combinator. The set of all closed λ−terms\lambda-terms is denoted by λ0\lambda^0

α−conversion\alpha-conversion​

It is the possibility of renaming binding (and bound) variables.

Let Mx→yM^{x \to y} denote the result of replacing every free occurrence of xx in MM by yy. defined as: λx.M=αλy.Mx→y\lambda x. M =_\alpha \lambda y. M^{x \to y}, provided that y∉FV(M)y \notin FV(M) and yy is not a binding variable in MM

Properties​

  1. Compatibility: if M=αNM =_\alpha N, then ML=αNLML =_\alpha NL, LM=αLNLM =_\alpha LN and, for arbitrary zz, λz.M=αλz.N\lambda z. M =_\alpha \lambda z. N
  2. Reflexivity: M=αMM =_\alpha M
  3. Symmetry: If M=αNM =_\alpha N then N=αMN =_\alpha M
  4. Transitivity: If both L=αML =_\alpha M and M=αNM =_\alpha N, then L=αNL =_\alpha N

α−variant\alpha-variant​

If M=αNM =_\alpha N, then MM and NN are said to be α−convertible\alpha-convertible or α−equivalent\alpha-equivalent. MM is called an α−variant\alpha-variant of NN (and vice versa)

Function evaluation process β−reduction\beta-reduction​

An expression of the form (λx.M)N(\lambda x. M)N can be rewritten to the expression M[x:=N]M[x:=N], i.e. the expressions MM in which every xx has been replaced with NN. We call this process β−reduction\beta-reduction of (λx.M)N(\lambda x. M)N to M[x:=N]M[x:=N]. e.g

  1. (λx.x2+1)(3)(\lambda x. x^2 + 1)(3) reduces to (x2+1)[x:=3](x^2 + 1)[x := 3] which is 32+13^2 + 1.
  2. (λz.(λx.x)(λy.y))(\lambda z. (\lambda x. x)(\lambda y.y)) reduces to (λz.(λy.y))(\lambda z. (\lambda y. y))
note

Application is the construction of new expression, not the execution of the expression. It is only after the reduction of the latter term that we obtain the result of the application

Substitution​

  1. x[x:=N]≡Nx[x:=N] \equiv N
  2. y[x:=N]≡yy[x:=N] \equiv y if x≢yx \not\equiv y
  3. (PQ)[x:=N]≡P[x:=N] Q[x:=N](PQ)[x := N] \equiv P[x := N]\ Q[x := N]
  4. (λy.P)[x:=N]≡λz.(Py→z[x:=N])(\lambda y. P)[x := N] \equiv \lambda z. (P^{y \to z}[x := N]), if λz.Py→z\lambda z. P^{y \to z} is an α−variant\alpha-variant of λy.P\lambda y. P such that z∉FV(N)z \notin FV(N)

One step β\beta-reduction →β\to_\beta​

The incentive to defining the relation →β\to_\beta is the presence of an application term where the first part is an abstraction: λx.M\lambda x. M. Since an abstraction can be thought of as representing a function, we can conceive of part NN as an argument for this function.

  1. Basis: (λx.M)N→βM[x:=N](\lambda x. M)N \to_\beta M[x:=N]
    1. The subterm of the form (λx.M)N(\lambda x. M)N on the left hand side is called a redex (from reducible expression). The subterm M[x:=N]M[x:=N] on the right hand side is called the contractum (of the redex)
  2. Compatibility: (M→βN)(M \to_\beta N), then ML→βNLML \to_\beta NL, LM→βLNLM \to_\beta LN and λx.M→βλx.N\lambda x. M \to_\beta \lambda x. N

Zero or more steps β\beta-reduction ↠β\twoheadrightarrow_\beta​

M↠βNM \twoheadrightarrow_\beta N if there is n≥0n \ge 0 and there are terms M0M_0 to MnM_n such that M0≡MM_0 \equiv M, Mn≡NM_n \equiv N and for all ii such that 0≤i<n0 \le i \lt n: Mi→βMi+1M_i \to_\beta M_{i+1}

Hence, if M↠βNM \twoheadrightarrow_\beta N, there exists a chain of single-step β\beta-reductions, starting with MM and ending with NN:

M≡M0→βM1→βM2→β⋯→βMn−2→βMn−1→βMn≡NM \equiv M_0 \to_\beta M_1 \to_\beta M_2 \to_\beta \dots \to_\beta M_{n-2} \to_\beta M_{n-1} \to_\beta M_{n} \equiv N

Lemma:

  1. ↠β\twoheadrightarrow_\beta extends →β\to_\beta, i.e. if M→βNM \to_\beta N, then M↠βNM \twoheadrightarrow_\beta N.
  2. ↠β\twoheadrightarrow_\beta is reflesive and transitive, i.e:
    1. (refl): for all M:M↠βMM: M \twoheadrightarrow_\beta M,
    2. (trans): for all LL, MM and NN: if L↠βML \twoheadrightarrow_\beta M and M↠βNM \twoheadrightarrow_\beta N then L↠βNL \twoheadrightarrow_\beta N.

β\beta-conversion, β\beta-equality, =β=_\beta​

M=βNM =_\beta N if there is an n≥0n \ge 0 and there are terms M0M_0 to MnM_n such that M0≡M,Mn≡NM_0 \equiv M, M_n \equiv N and for all ii such that 0≤i<n0 \le i \lt n: either Mi→βMi+1M_i \to_\beta M_{i+1} or Mi+1→βMiM_{i+1} \to_\beta M_i

For example: (λy.yv)z=β(λx.zx)v(\lambda y. yv)z =_\beta (\lambda x. zx)v since we have the following chain, where ←β\leftarrow_\beta is the inverse of →β\to_\beta:

(λy.yv)z→βzv←β(λx.zx)v (\lambda y. yv)z \to_\beta zv \leftarrow_\beta (\lambda x. zx)v

=β=_\beta is an equivalence relation, hence reflexive, symmetric and transitive

β\beta-normal form (β\beta-nf)​

  1. MM is in β\beta-normal form if MM does not contain any redex
  2. MM has a β\beta-normal form if there is an NN in β\beta-normal form that M=βNM =_\beta N. Such an N is a β\beta-normal form of MM

When MM is in β\beta-nf, then M↠βNM \twoheadrightarrow_\beta N implies M≡NM \equiv N

Fixed point theorem​

For all L∈ΛL \in \Lambda there is M∈ΛM \in \Lambda such that LM=βMLM =_\beta M. e.g the function f(n)=n2f(n) = n^2, has two fixed points 00 and 11. The successor function s(n)=n+1s(n) = n + 1 has no fixed point at all.